package service

import (
	"chaowan/data_source"
	"chaowan/models"
)

func Vipsj(user models.User, price float64) {
	var vipgift []models.Vipgiftsql
	data_source.Db.Debug().Model(&models.Vipgift{}).Order("dengji asc").Find(&vipgift)
	//fmt.Println(vipgift)
	var vipdj int64
	uservippirce := user.Vipprice + price
	for _, vip := range vipgift {
		if vip.Price <= uservippirce {
			vipdj = vip.Dengji
		} else {
			break
		}
	}
	userup := models.User{
		Vip:      vipdj,
		Vipprice: uservippirce,
	}
	data_source.Db.Where("id = ?", user.ID).Updates(&userup)
}
